package com.newland.util;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
/**
 *Description:
 *Version:1.0.0
 *@author shihb
 *@date 2020/3/30 15:23
 */
public class MyUtils {
  private static Properties config;

  public static Properties getConfig(){
    return config;
  }
  public static  void loadConfigFile(String configPath) {
    config = new Properties();
    try {
      config.load(new BufferedInputStream(new FileInputStream(configPath)));
    } catch (IOException e) {
      throw new RuntimeException("IO error", e);
    }

  }
  public static void loadConfigFile(){
    String fileName = "config.properties";
    String CONFIG_FILE_NAME = Thread.currentThread().getContextClassLoader().getResource(fileName).getFile();
    System.out.println(CONFIG_FILE_NAME);
    Properties configFile = new Properties();
    try {
      File file = new File(CONFIG_FILE_NAME);
      FileInputStream fis = new FileInputStream(file);
      configFile.load(fis);
      fis.close();
    } catch (FileNotFoundException ex) {
      throw new RuntimeException("File [" + CONFIG_FILE_NAME + "] not found", ex);
    } catch (IOException ex) {
      throw new RuntimeException("IO error", ex);
    } catch (Exception ex) {
      throw new RuntimeException("Load config error", ex);
    }
    config = configFile;
  }
}
